using UnityEngine.UI;

public class DialogShop : GenericDialog
{
	public Button buttonUnlockArenas;

	public Text textPriceUnlockArenas;

	public Text textBonusLivesUnlockArenas;

	public Button buttonRemoveAds;

	public Text textPriceRemoveAds;

	public Text textBonusLivesRemoveAds;

	public Button buttonBuyLives1;

	public Button buttonBuyLives2;

	public Button buttonBuyLives3;

	public Text textQuantityBuyLives1;

	public Text textQuantityBuyLives2;

	public Text textQuantityBuyLives3;

	public Text textPriceBuyLives1;

	public Text textPriceBuyLives2;

	public Text textPriceBuyLives3;

	public Button buttonBuyWildcards1;

	public Button buttonBuyWildcards2;

	public Button buttonBuyWildcards3;

	public Text textQuantityBuyWildcards1;

	public Text textQuantityBuyWildcards2;

	public Text textQuantityBuyWildcards3;

	public Text textPriceBuyWildcards1;

	public Text textPriceBuyWildcards2;

	public Text textPriceBuyWildcards3;

	private IAPManager.ProductType purchaseProductType;

	//private void OnEnable()
	//{
	//	if (Globals.appState != 0 && Globals.appState != AppState.unknown)
	//	{
	//		UpdateControls();
	//		Economy.LivesChangedEvent += OnLivesChanged;
	//		Economy.WildcardsChangedEvent += OnWildcardsChanged;
	//		Economy.PurchaseFinishedEvent += OnPurchaseFinished;
	//		GenericDialog.FireDialogEnabledEvent();
	//		CustomAnalytics.LogUIEvent("Menu", "Cart");
	//	}
	//}

	//private void OnDisable()
	//{
	//	if (Globals.appState != 0 && Globals.appState != AppState.unknown)
	//	{
	//		Economy.LivesChangedEvent -= OnLivesChanged;
	//		Economy.WildcardsChangedEvent -= OnWildcardsChanged;
	//		Economy.PurchaseFinishedEvent -= OnPurchaseFinished;
	//	}
	//}

	private void OnLivesChanged(int deltaLives)
	{
		UpdateControls();
	}

	private void OnWildcardsChanged(int deltaWildcards)
	{
		UpdateControls();
	}

	private void OnPurchaseFinished(bool succes)
	{
		UpdateControls();
	}

	private void UpdateControls()
	{
		//buttonUnlockArenas.interactable = Economy.CanPurchase(IAPManager.ProductType.Unlock);
		//textPriceUnlockArenas.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.Unlock);
		//textBonusLivesUnlockArenas.text = EconomySettings.livesBonusForUnlockPurchase.ToString();
		//buttonRemoveAds.interactable = Economy.CanPurchase(IAPManager.ProductType.RemoveAds);
		//textPriceRemoveAds.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.RemoveAds);
		//textBonusLivesRemoveAds.text = EconomySettings.livesBonusForRemoveAdPurchase.ToString();
		//buttonBuyLives1.interactable = Economy.CanPurchase(IAPManager.ProductType.LivesPack1);
		//buttonBuyLives2.interactable = Economy.CanPurchase(IAPManager.ProductType.LivesPack2);
		//buttonBuyLives3.interactable = Economy.CanPurchase(IAPManager.ProductType.LivesPack3);
		//textQuantityBuyLives1.text = Economy.GetQuantityForProduct(IAPManager.ProductType.LivesPack1).ToString();
		//textQuantityBuyLives2.text = Economy.GetQuantityForProduct(IAPManager.ProductType.LivesPack2).ToString();
		//textQuantityBuyLives3.text = Economy.GetQuantityForProduct(IAPManager.ProductType.LivesPack3).ToString();
		//textPriceBuyLives1.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.LivesPack1);
		//textPriceBuyLives2.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.LivesPack2);
		//textPriceBuyLives3.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.LivesPack3);
		//buttonBuyWildcards1.interactable = Economy.CanPurchase(IAPManager.ProductType.WildcardsPack1);
		//buttonBuyWildcards2.interactable = Economy.CanPurchase(IAPManager.ProductType.WildcardsPack2);
		//buttonBuyWildcards3.interactable = Economy.CanPurchase(IAPManager.ProductType.WildcardsPack3);
		//textQuantityBuyWildcards1.text = Economy.GetQuantityForProduct(IAPManager.ProductType.WildcardsPack1).ToString();
		//textQuantityBuyWildcards2.text = Economy.GetQuantityForProduct(IAPManager.ProductType.WildcardsPack2).ToString();
		//textQuantityBuyWildcards3.text = Economy.GetQuantityForProduct(IAPManager.ProductType.WildcardsPack3).ToString();
		//textPriceBuyWildcards1.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.WildcardsPack1);
		//textPriceBuyWildcards2.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.WildcardsPack2);
		//textPriceBuyWildcards3.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.WildcardsPack3);
	}

	public void OnButtonUnlock()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Menu", "Cart - Unlock All");
        UserInterface.GetInstance().dialogPurchaseTips.Reset();
        AdManager.single.ShowVideo(() =>
		{
			Economy.instance.IAPSuccess(IAPManager.ProductType.Unlock);
			UserInterface.GetInstance().dialogPurchaseTips.PurchaseSuccess();

        });
        UserInterface.GetInstance().OnDisplayPurchaseTips();
    }

	public void OnButtonAds()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Menu", "Cart - Remove Ads");
		UserInterface.GetInstance().DoPurchase(IAPManager.ProductType.RemoveAds);
	}

	public void OnButtonLives1()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Menu", "Cart - Lives 1");
		UserInterface.GetInstance().DoPurchase(IAPManager.ProductType.LivesPack1);
	}

	public void OnButtonLives2()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Menu", "Cart - Lives 2");
        UserInterface.GetInstance().dialogPurchaseTips.Reset();
        AdManager.single.ShowVideo(() =>
		{
			Economy.instance.IAPSuccess(IAPManager.ProductType.LivesPack2);
            UserInterface.GetInstance().dialogPurchaseTips.PurchaseSuccess();
        });
        UserInterface.GetInstance().OnDisplayPurchaseTips();
    }

	public void OnButtonLives3()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Menu", "Cart - Lives 3");
		UserInterface.GetInstance().DoPurchase(IAPManager.ProductType.LivesPack3);
	}

	public void OnButtonWildcard1()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Menu", "Cart - Wildcards 1");
		UserInterface.GetInstance().DoPurchase(IAPManager.ProductType.WildcardsPack1);

    }

	public void OnButtonWildcard2()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Menu", "Cart - Wildcards 2");
        UserInterface.GetInstance().dialogPurchaseTips.Reset();
        AdManager.single.ShowVideo(() =>
		{
			Economy.instance.IAPSuccess(IAPManager.ProductType.WildcardsPack2);
            UserInterface.GetInstance().dialogPurchaseTips.PurchaseSuccess();
        });
        UserInterface.GetInstance().OnDisplayPurchaseTips();
    }

	public void OnButtonWildcard3()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Menu", "Cart - Wildcards 3");
		UserInterface.GetInstance().DoPurchase(IAPManager.ProductType.WildcardsPack3);
	}
}
